<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

<html>
	<head>
		<title>IdeaPad - Ideas</title>
		<link rel="stylesheet" type="text/css" href="styles/main.css">
		<link rel="stylesheet" type="text/css" href="styles/buttons.css">
	</head>
	<body>
		<div class="header">
			<html:link action="/default"><img src="/IdeaPad/images/ideapad_logo.png" alt="logo" border="0"/></html:link>
			<%
		if(session.getAttribute("username") == null || session.getAttribute("username") == ""){
			%>
			<html:link page="/form/login.jsp" styleClass="menubuttons">Login</html:link>
			<html:link page="/form/registerUser.jsp" styleClass="menubuttons">Register</html:link>
			<%
		}
		else{
			%>
			Hello 
			<%=
			session.getAttribute("username").toString() %>
			<html:link action="viewGroups" styleClass="menubuttons">Groups</html:link>
			<html:link action="manageGroups" styleClass="menubuttons">Manage Groups</html:link>
			<html:link page="/form/editUserSettings.jsp" styleClass="menubuttons">Settings</html:link>
			<html:link action="logout" styleClass="menubuttons">Logout</html:link>
			<%
		}
		 %>
		</div>
		<h1>
			Idea List for "<bean:write name="ideaListForm" property="groupName"/>"
		</h1>
		<table border="1">
			<tbody>
				<%-- Set table header --%>
				<tr>
					<td>
						Name
					</td>
					<td>
						Abstract
					</td>
					<td>
						Created By
					</td>
					<td>
						Vote Count
					</td>
				</tr>
				<%-- Check if any ideas exist --%>
				<logic:empty name="ideaListForm" property="ideas">
					<tr>
						<td colspan="4">
							No ideas...
						</td>
					</tr>
				</logic:empty>
				<logic:notEmpty name="ideaListForm" property="ideas">
					<logic:iterate name="ideaListForm" property="ideas" id="idea">
						<tr>
							<td>
								<html:link action="/showIdea" paramName="idea" paramProperty="ideaId" paramId="ideaId">
									<bean:write name="idea" property="ideaName" />
								</html:link>
							</td>
							<td>
								<bean:write name="idea" property="abstractText" />
							</td>
							<td>
								<bean:write name="idea" property="userName" />
							</td>
							<td>
								<bean:write name="idea" property="voteCount" />
							</td>
						</tr>
					</logic:iterate>
				</logic:notEmpty>
				<tr>
					<td colspan="4">
						<html:link page="/form/submitIdea.jsp">Submit your own idea</html:link>
					</td>
				</tr>
			</tbody>
		</table>
	</body>
</html>
